package com.atom.process.cnmuseum.bm.dao.task;

import com.atom.common.dao.AvensCommonDao;
import com.atom.common.exception.AvensNullPointerException;
import com.atom.common.remote.user.UserUtil;
import com.atom.process.cnmuseum.bm.entity.task.BmTaskDO;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public class BmTaskDao extends AvensCommonDao<BmTaskDO> {

    public BmTaskDO findByTaskId(String taskId) {
        List<BmTaskDO> list = super.findByProperty("taskId", taskId);
        if (list == null || list.size() == 0) {
            throw new AvensNullPointerException("TaskDO is null where taskId = " + taskId);
        } else {
            return list.get(0);
        }
    }

    public void createADO(UserUtil user, String processInstanceId, String taskId, String biaoTi, String gcxxid) {
        BmTaskDO ado = new BmTaskDO();
        ado.setShenQingRen(user.getUserid());
        ado.setShenQingRenText(user.getUsername());
        ado.setShenQingBuMen(user.getOrgid());
        ado.setShenQingBuMenText(user.getOrgname());
        ado.setShenQingRiQi(new Date());
        ado.setProcessId(processInstanceId);
        ado.setTaskId(taskId);
        ado.setBiaoTi(biaoTi);
        ado.setGcxxid(gcxxid);
        save(ado);
    }

}
